package com.shiku.imserver.message.hander;

import com.shiku.imserver.common.annotation.MessageCommandAnnotation;
import com.shiku.imserver.common.hander.AbstractMessageHandler;
import com.shiku.imserver.common.message.PacketVO;
import com.shiku.imserver.common.message.ServerReqMessage;
import com.shiku.imserver.common.packets.ImPacket;
import com.shiku.imserver.common.proto.MessageProBuf;
import com.shiku.imserver.common.utils.ProBufUtils;
import com.shiku.imserver.service.IMBeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;

public class ServerMessageHandler extends AbstractMessageHandler {
    private static final Logger logger = LoggerFactory.getLogger(ServerMessageHandler.class);

    @MessageCommandAnnotation(command = 200)
    public PacketVO serverMessageHandler(ImPacket packet, ChannelContext channelContext) {
        try {
            ServerReqMessage message = (ServerReqMessage) ProBufUtils.decoderMessageBody(packet.getBytes(), MessageProBuf.ServerReqMessageProBuf.getDescriptor(), ServerReqMessage.class);
            if (message != null) {
                message.getMessageHead().getFrom();
                switch (message.getType()) {
                    case 1:
                        IMBeanUtils.getRedisService().initConfig();
                    case 2:
                        IMBeanUtils.getBeanManager().getServiceRepository().getAllKeyWord();
                        break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
